//
//  NSEUtils.h
//  NSESolver
//
//  Created by Teseo on 03/05/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#ifndef __NSE_UTILS_UTILS_H__
#define __NSE_UTILS_UTILS_H__

#include "CartesianTopology.h"

namespace nsesolver {

    /// cardinal directions
    enum CardinalDirections {
        North,
        South,
        West,
        East
    };
    
    /**
     \brief gets the dimention and direction for the specific cardinal direction
     \param the direction
     \param [IN,OUT] dimention (eg:x,y)
     \param [IN,OUT] direction
     */
    inline void getDimDir(const CardinalDirections carDir, int *dim, int *dir)
    {
        switch (carDir) {
            case North:
                *dim=1;
                *dir=1;
                break;
            case South:
                *dim=1;
                *dir=-1;
                break;
            case East:
                *dim=0;
                *dir=1;
                break;
            case West:
                *dim=0;
                *dir=-1;
                break;
        }
    }
    /**
     \brief return if a processor has a boundary in a specific direction
     \param the direction
     \param the topology in which the processor is
     */
    inline bool isBoundary(const CardinalDirections carDir, const mpi::CartesianTopology &cart)
    {
        int dim(0), dir(0);
        
        getDimDir(carDir, &dim, &dir);
        
        return cart.isBoundary(dim, dir);
    }
}

#endif
